package com.shop2cn.iapi.sqoptrade.testcase;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Random;

import com.shop2cn.iapi.sqoptrade.parameter.enums.CouponApplianceTypeEnum;
import com.ymttest.business.service.shenqi.*;
import org.apache.commons.collections.CollectionUtils;
import org.junit.*;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.common.collect.Lists;
import com.shop2cn.iapi.points.enums.PointsBizTypeEnum;
import com.shop2cn.iapi.points.pojo.CreditPolicy;
import com.shop2cn.iapi.points.resp.CalcOrderCreditResp;
import com.shop2cn.iapi.shenqisettlement.parameter.bean.AgentProductBean;
import com.shop2cn.iapi.sqoptrade.parameter.enums.CouponMainTypeEnum;
import com.shop2cn.iapi.sqoptrade.parameter.enums.CouponTypeEnum;
import com.shop2cn.iapi.sqoptrade.parameter.enums.PromotionTypeEnum;
import com.shop2cn.iapi.sqoptrade.parameter.req.CdfDeductCouponBeforePlaceReq;
import com.shop2cn.iapi.sqoptrade.parameter.req.GetProductTaxFeeReq;
import com.shop2cn.iapi.sqoptrade.parameter.utill.Utils;
import com.shop2cn.iapi.sqoptrade.parameter.vo.CatalogApportionVo;
import com.shop2cn.iapi.sqoptrade.parameter.vo.CouponVo;
import com.shop2cn.iapi.sqoptrade.parameter.vo.OrderGroupVoForTax;
import com.shop2cn.iapi.sqoptrade.parameter.vo.OrderItemVoForTax;
import com.shop2cn.iapi.sqoptrade.parameter.vo.OrderVoForCdfCoupon;
import com.shop2cn.iapi.sqoptrade.parameter.vo.OrderVoForTax;
import com.shop2cn.iapi.sqoptrade.parameter.vo.ProductVoForCdfCoupon;
import com.shop2cn.iapi.sqoptrade.parameter.vo.SellerPromotionVo;
import com.shop2cn.iapi.sqoptrade.resp.CdfDeductCouponBeforePlaceResp;
import com.shop2cn.iapi.sqoptrade.resp.GetProductTaxFeeResp;
import com.shop2cn.iapi.sqoptrade.resp.vo.CouponAmountVo;
import com.shop2cn.iapi.sqoptrade.resp.vo.IntegralDeductionInfoVo;
import com.shop2cn.iapi.sqoptrade.service.GetProductTaxFeeCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.shenqi.bean.ShenqiUserSet;
import com.ymttest.database.sharding.db.sharding.model.OrderCouponDetailPo;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;

public class Ts_SqGetProductTaxFee {

	private static GetProductTaxFeeReq getProductTaxFeeReq;
	private static GetProductTaxFeeCall getProductTaxFeeCall;

	private static long autotest_goodsOwnerId = Long.valueOf(EnvSetup
			.getData("autotest_goodsOwnerId"));
	private static long cdfMembergoodsOwnerId = ShenqiUserSet.cdfMembergoodsOwnerId;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("计算商品税费、服务费、区域折扣");
	}

	@Before
	public void caseUp() {
		getProductTaxFeeReq = new GetProductTaxFeeReq();
		getProductTaxFeeCall = new GetProductTaxFeeCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getProductTaxFeeCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	public OrderItemVoForTax buildStandOrderItemVoForTax(AgentProductBean productBean) {
		
		OrderItemVoForTax orderItemVoForTax = new OrderItemVoForTax();

		orderItemVoForTax.setCatalogId(productBean.getCatalogList().get(0));
		orderItemVoForTax.setFreight(new BigDecimal(
				new Random().nextInt(20) + 10));
		orderItemVoForTax.setProdTaxRate(null);
		orderItemVoForTax.setProductId(productBean.getProductId());
		orderItemVoForTax.setProductNum(new Random().nextInt(4) + 2);
		orderItemVoForTax.setProductPrice(new BigDecimal("1542.00"));
		
		return orderItemVoForTax;
	}

	public OrderVoForTax buildStandOrderVoForTax(Long goodsOwnerId,
			List<OrderItemVoForTax> orderItemVoForTaxs) {

		OrderVoForTax orderVoForTax = new OrderVoForTax();

		orderVoForTax.setGoodsOwnerId(goodsOwnerId);
		orderVoForTax.setOrderItems(orderItemVoForTaxs);

		return orderVoForTax;
	}

	public GetProductTaxFeeReq buildStandGetProductTaxFeeReq(
			AgentProductBean productBean, Long goodsOwnerId,
			BigDecimal prodTaxRate) {

		return buildStandGetProductTaxFeeReq(productBean, goodsOwnerId,
				prodTaxRate, false);
	}

	public GetProductTaxFeeReq buildStandGetProductTaxFeeReq(
			AgentProductBean productBean, Long goodsOwnerId,
			BigDecimal prodTaxRate, boolean useCoupon) {

		OrderItemVoForTax orderItemVoForTax = new OrderItemVoForTax();
		Long sellerId = productBean.getSellerId();

		orderItemVoForTax.setCatalogId(productBean.getCatalogList().get(0));
		orderItemVoForTax.setFreight(new BigDecimal(
				new Random().nextInt(20) + 10));
		orderItemVoForTax.setProdTaxRate(prodTaxRate);
		orderItemVoForTax.setProductId(productBean.getProductId());
		orderItemVoForTax.setProductNum(new Random().nextInt(4) + 2);
		orderItemVoForTax.setProductPrice(new BigDecimal("1542.00"));

		OrderVoForTax orderVoForTax = new OrderVoForTax();

		orderVoForTax.setGoodsOwnerId(goodsOwnerId);
		orderVoForTax.setOrderItems(Lists.newArrayList(orderItemVoForTax));

		OrderGroupVoForTax orderGroupVoForTax = new OrderGroupVoForTax();

		orderGroupVoForTax.setSellerId(sellerId);
		orderGroupVoForTax.setOrders(Lists.newArrayList(orderVoForTax));

		if (useCoupon) {

			// 商家券
			CouponVo sellerCoupon1 = SqTradingCallService.createSellerCouponVo(
					20238699L, sellerId, new BigDecimal(30), BigDecimal.TEN);

			orderGroupVoForTax.setSellerCoupon(sellerCoupon1);
		}

		getProductTaxFeeReq.setOrderGroups(Lists
				.newArrayList(orderGroupVoForTax)); 
		getProductTaxFeeReq.setFromShenqi(true);
		getProductTaxFeeReq.setDiscount(BigDecimal.TEN);
		getProductTaxFeeReq.setCurrency(productBean.getCurrency());
		getProductTaxFeeReq.setUserId(20238699L);

		return getProductTaxFeeReq;
	}

	public void verify() throws Exception {

		BigDecimal serviceRate = BigDecimal.ZERO;

		List<BigDecimal> orderItemWeightsOnFreight = new ArrayList<BigDecimal>();
		List<BigDecimal> orderWeightsDiscount = new ArrayList<BigDecimal>();

		String currency = getProductTaxFeeReq.getCurrency();

		if (!getProductTaxFeeReq.isFromShenqi())
			getProductTaxFeeReq.setDiscount(BigDecimal.ZERO);

		// 所有订单
		List<OrderVoForTax> allOrders = new ArrayList<OrderVoForTax>();
		BigDecimal totalProxyProfit = BigDecimal.ZERO;

		for (OrderGroupVoForTax orderGroupVo : getProductTaxFeeReq
				.getOrderGroups()) {

			BigDecimal totalProductPriceInSellerCoupon = BigDecimal.ZERO;
			
			serviceRate = orderGroupVo.getServiceRate();
			
			Boolean isCDFCoupon = false;
			
			List<CouponVo> sellerCoupons = null;
			
			CouponVo sellerCoupon = orderGroupVo.getSellerCoupon();

			// 中免不使用优惠券叠加
			if (null != sellerCoupon) {

				sellerCoupons = new ArrayList<>();

				isCDFCoupon = SqTradingCallService.isCDFCoupon(Utils
						.zeroIfNull(sellerCoupon.getCouponSource()));

				sellerCoupons.add(sellerCoupon);
			}

			if (null != orderGroupVo.getSellerCoupons()) {

				if (null == sellerCoupons)
					sellerCoupons = new ArrayList<>();

				for (CouponVo c : orderGroupVo.getSellerCoupons()) {

					isCDFCoupon = SqTradingCallService.isCDFCoupon(Utils
							.zeroIfNull(c.getCouponSource()));
					sellerCoupons.add(c);
				}
			}

			for (OrderVoForTax orderVoForTax : orderGroupVo.getOrders()) {

				BigDecimal orderFreight = BigDecimal.ZERO;
				BigDecimal orderWeightOnDiscount = BigDecimal.ZERO;

				long sellerId = orderGroupVo.getSellerId();
				
				// 如果是兑换券
				if (sellerCoupons != null)
					sellerCoupon = sellerCoupons.get(0);
				
				if (null != sellerCoupons) {
					for (CouponVo sCoupon : sellerCoupons) {
						if (sCoupon.getCouponType() == 5) {

							String applianceTargets = sCoupon
									.getApplianceTargets().get(0);

							OrderItemVoForTax exchangeCouponOrderItemVo = orderVoForTax
									.getOrderItems()
									.stream()
									.filter(orderItems -> orderItems
											.getCatalogId().equalsIgnoreCase(
													applianceTargets))
									.findAny().orElse(null);

							OrderItemVoForTax orderItemVo = null;

							if (null != exchangeCouponOrderItemVo) {
								if (exchangeCouponOrderItemVo.getProductNum() > 1) {

									orderItemVo = (OrderItemVoForTax) exchangeCouponOrderItemVo
											.clone();
									exchangeCouponOrderItemVo
											.setProductNum(exchangeCouponOrderItemVo
													.getProductNum() - 1);

									orderItemVo.setCatalogId("speecc"
											+ exchangeCouponOrderItemVo
													.getCatalogId());
									orderItemVo.setProductNum(1);

									// 费率分摊
									BigDecimal[] freightWeight = new BigDecimal[2];

									freightWeight[0] = exchangeCouponOrderItemVo
											.getProductPrice()
											.multiply(
													new BigDecimal(
															exchangeCouponOrderItemVo
																	.getProductNum()));
									freightWeight[1] = orderItemVo
											.getProductPrice();

									BigDecimal freight[] = Utils
											.apportionByWeights(Utils
													.zeroIfNull(orderItemVo
															.getFreight()),
													freightWeight);

									exchangeCouponOrderItemVo
											.setFreight(freight[0]);
									orderItemVo.setFreight(freight[1]);

									orderVoForTax.getOrderItems().add(orderItemVo);
								} else {

									orderItemVo = exchangeCouponOrderItemVo;
									orderItemVo.setCatalogId("speecc"
											+ exchangeCouponOrderItemVo
													.getCatalogId());
								}
							}
						}
					}
				}

				for (OrderItemVoForTax orderItemVoForTax : orderVoForTax
						.getOrderItems()) {

					orderFreight = orderFreight.add(Utils
							.zeroIfNull(orderItemVoForTax.getFreight()));
					
					BigDecimal proxyPrice = BigDecimal.ZERO;
					BigDecimal productPriceInSellerCoupon = BigDecimal.ZERO;

					// 累计订单的总成交价
					BigDecimal totalProductPrice = orderItemVoForTax
							.getProductPrice().multiply(
									new BigDecimal(orderItemVoForTax
											.getProductNum()));

					// 获得该商品的利润
					if (sellerId == orderVoForTax.getGoodsOwnerId())
						totalProxyProfit = totalProductPrice;

					else {

						proxyPrice = SqTradingProductService
								.getProxyChainInfo(
										orderItemVoForTax.getCatalogId(),
										sellerId).getFromParentPrice();

						serviceRate = BigDecimal.ZERO;
					}

					// 获得该商品的毛利润
					BigDecimal productProxyProfit = orderItemVoForTax
							.getProductPrice()
							.subtract(proxyPrice)
							.multiply(
									new BigDecimal(orderItemVoForTax
											.getProductNum()));

					orderItemVoForTax
							.setOrderItemGrossProfit(productProxyProfit);

					orderItemWeightsOnFreight.add(totalProductPrice);
					orderVoForTax.setTotalProductPrice(orderVoForTax
							.getTotalProductPrice().add(totalProductPrice));	
					
					int couponCount = 0;
					
					if (null != sellerCoupons) {
						if (sellerCoupons.size() == 0) {

							orderVoForTax.getOrderItemWeightsOnSellerCoupon().add(
									BigDecimal.ZERO);
							productPriceInSellerCoupon = BigDecimal.ZERO;
						} else {
							
							Boolean addTotalProductPriceInSellerCoupon = false;
							
							for (CouponVo c : sellerCoupons) {
								if (c != null
										&& couponApplicable(orderItemVoForTax, c)
										&& !Utils.falseIfNull(orderItemVoForTax
												.getExchangeBuy())) {

									couponCount = couponCount + 1;
									
									if (isCDFCoupon) {

										orderVoForTax.setSellerCouponCode(c.getCouponCode());
										orderVoForTax.setSellerCouponSource(c
												.getCouponSource());
										orderVoForTax.setSellerCouponType(c.getCouponType());
									} else {

										// 如果是多个优惠券，则订单上只保留第一张券的信息
										orderVoForTax.setSellerCouponCode(sellerCoupons
												.get(0).getCouponCode());
										orderVoForTax.setSellerCouponSource(sellerCoupons
												.get(0).getCouponSource());
										orderVoForTax.setSellerCouponType(couponCount > 1 ? -1
												: sellerCoupon.getCouponType());

										productPriceInSellerCoupon = totalProductPrice;
										
										if (!addTotalProductPriceInSellerCoupon) {
											
											// 订单中适用商家优惠券的成交价总额
											orderVoForTax.setTotalProductPriceInSellerCoupon(orderVoForTax
													.getTotalProductPriceInSellerCoupon()
													.add(productPriceInSellerCoupon));

											totalProductPriceInSellerCoupon = totalProductPriceInSellerCoupon
													.add(productPriceInSellerCoupon);
											orderVoForTax.getOrderItemWeightsOnSellerCoupon()
													.add(totalProductPrice);
										}

										addTotalProductPriceInSellerCoupon = true;
									}
								}
							}
						}
					}

					if (getProductTaxFeeReq.getDiscount() != null) {

						// 商品分摊折扣的权重按照商品价格
						orderVoForTax.getOrderItemWeightsOnDiscount().add(
								totalProductPrice);

						// 订单分摊折扣的权重按照商品利润
						orderWeightOnDiscount = orderWeightOnDiscount
								.add(totalProxyProfit);
					}
				}

				orderVoForTax.setFreight(orderFreight);

				allOrders.add(orderVoForTax);

				orderWeightsDiscount.add(orderWeightOnDiscount);

				orderGroupVo.getOrderWeightsOnSellerCoupon().add(
						orderVoForTax.getTotalProductPriceInSellerCoupon());
			}
			
			// 分摊商家优惠活动金额
			apportionSellerPromotions(orderGroupVo);
			
			// 计算区域折扣到订单
			calcRegionDiscountToOrder(orderGroupVo, currency);

			// 分摊区域折扣到订单项
			apportionRegionDiscountToOrderItem(orderGroupVo, currency);

			int index = 0;
			
			if (null != sellerCoupons) {
				for (CouponVo sCoupon : sellerCoupons) {
					if (sCoupon != null) {
						if (isCDFCoupon) {

							List<OrderItemVoForTax> orderItemList = new ArrayList<>();
							List<OrderVoForCdfCoupon> orderVoList = new ArrayList<>();

							for (OrderVoForTax order : orderGroupVo.getOrders()) {

								OrderVoForCdfCoupon orderVoForCdfCoupon = new OrderVoForCdfCoupon();

								List<ProductVoForCdfCoupon> productVoList = new ArrayList<>();

								for (OrderItemVoForTax orderItem : order.getOrderItems()) {

									ProductVoForCdfCoupon productVoForCdfCoupon = new ProductVoForCdfCoupon();

									BigDecimal productPriceExcludeSellerPromotionAndRegionDiscount = orderItem
											.getProductPrice()
											.multiply(
													new BigDecimal(orderItem
															.getProductNum()))
											.subtract(
													Utils.zeroIfNull(orderItem
															.getSellerPromotionValue()))
											.subtract(
													Utils.zeroIfNull(orderItem
															.getRegionDiscountValue()))
											.divide(new BigDecimal(
													orderItem.getProductNum()),
													2, BigDecimal.ROUND_DOWN);

									productVoForCdfCoupon.setCatalogId(orderItem
											.getCatalogId());
									productVoForCdfCoupon
											.setPrice(productPriceExcludeSellerPromotionAndRegionDiscount);
									productVoForCdfCoupon.setProductId(orderItem
											.getProductId());
									productVoForCdfCoupon.setProductNum(orderItem
											.getProductNum());
									productVoForCdfCoupon.setSkuId(orderItem
											.getSku());
									productVoForCdfCoupon.setSubProduct(orderItem
											.getSubProduct());
									productVoForCdfCoupon
											.setExchangeBuy(orderItem
													.getExchangeBuy());
									productVoForCdfCoupon
											.setDomesticProduct(orderItem
													.isDomesticProduct());

									productVoList.add(productVoForCdfCoupon);

									orderItemList.add(orderItem);
								}

								orderVoForCdfCoupon.setProductVoList(productVoList);

								orderVoList.add(orderVoForCdfCoupon);
							}

							CdfDeductCouponBeforePlaceReq cdfDeductCouponBeforePlaceReq = new CdfDeductCouponBeforePlaceReq();

							// 领取cdf优惠券
							CDFMemberService.getCdfCoupon(orderGroupVo
									.getSellerCoupon().getCouponType(), orderGroupVo
									.getSellerId() == 502665591 ? 2 : 1,
											getProductTaxFeeReq.getUserId());

							orderGroupVo.getSellerCoupon().setCouponCode(
									CDFMemberService.getLatestUnuseCdfCoupon(
											getProductTaxFeeReq.getUserId(),
											orderGroupVo.getSellerId()));

							cdfDeductCouponBeforePlaceReq.setCouponVo(orderGroupVo
									.getSellerCoupon());
							cdfDeductCouponBeforePlaceReq.setSellerId(orderGroupVo
									.getSellerId());
							cdfDeductCouponBeforePlaceReq.setUserId(getProductTaxFeeReq
									.getUserId());
							cdfDeductCouponBeforePlaceReq
									.setOrderVoList(orderVoList);
							cdfDeductCouponBeforePlaceReq.setCurrency(Utils
									.nullIsCNY(getProductTaxFeeReq.getCurrency()));

							CdfDeductCouponBeforePlaceResp cdfDeductCouponBeforePlaceResp = SqTradingCallService
									.cdfDeductCouponBeforePlace(cdfDeductCouponBeforePlaceReq);

							// 分摊中免优惠券到订单项
							apportionCDFCouponToOrderItem(orderItemList,
									cdfDeductCouponBeforePlaceResp
											.getCouponAmountVoList());

							for (OrderVoForTax order : orderGroupVo.getOrders()) {

								BigDecimal orderCouponValue = order.getOrderItems()
										.stream()
										.map(o -> o.getSellerCouponValue())
										.reduce(BigDecimal.ZERO, BigDecimal::add);
								order.setSellerCouponValue(orderCouponValue);
							}
						} else {

							if (sCoupon.getCouponType() == 5) {

							} else {
		
								// 分摊商家优惠券
								if (totalProductPriceInSellerCoupon
										.compareTo(sellerCoupon.getCouponValue()) <= 0) {
									throw new IllegalArgumentException(
											"商家适用优惠券的商品成交价总额必须大于商家优惠券总额:"
													+ orderGroupVo.getSellerId());
								}
							}

							// 分摊商家优惠券到订单
							apportionSellerCouponToOrder(orderGroupVo, currency, sCoupon, index);

							// 分摊商家优惠券到订单项
							apportionSellerCouponToOrderItem(orderGroupVo, currency, index);
							
							totalProductPriceInSellerCoupon = totalProductPriceInSellerCoupon.subtract(sCoupon.getCouponValue());
						}
						
						index = index + 1;
					}
				}
			}
		}

		// 分摊折扣
		if (getProductTaxFeeReq.getDiscount() != null) {

			// 如果总利润为0，则订单分摊折扣的权重按照商品价格
			if (totalProxyProfit.compareTo(BigDecimal.ZERO) == 0) {

				orderWeightsDiscount.clear();

				for (OrderVoForTax order : allOrders)
					orderWeightsDiscount.add(order.getTotalProductPrice());
			}

			boolean isNegate = getProductTaxFeeReq.getDiscount()
					.compareTo(BigDecimal.ZERO)  == -1 ? true : false;

			apportionOrderDiscountToOrder(allOrders,
					getProductTaxFeeReq.getDiscount(), orderWeightsDiscount,
					getProductTaxFeeReq.getCurrency(), isNegate);
			apportionOrderDiscountToOrderItem(allOrders,
					getProductTaxFeeReq.getCurrency(), isNegate);
		}

		HashMap<String, BigDecimal> map = calcExpectedOrderTaxFee(allOrders,
				serviceRate);

		BigDecimal taxFee = new BigDecimal(getProductTaxFeeCall.getTaxFee());
		BigDecimal serviceAmount = new BigDecimal(
				getProductTaxFeeCall.getServiceAmount());
		BigDecimal regionDiscountAmount = new BigDecimal(
				getProductTaxFeeCall.getRegionDiscountAmount());

		DataUtil.verifyDecimalEquals(map.get("orderTaxFee"), taxFee, "验证taxFee");
		DataUtil.verifyDecimalEquals(map.get("orderServiceAmount"),
				serviceAmount, "验证ServiceAmount");
		DataUtil.verifyDecimalEquals(map.get("regionDiscountAmount"),
				regionDiscountAmount, "验证RegionDiscountAmount");

		BigDecimal payableAmount = allOrders
				.stream()
				.map(OrderVoForTax::getTotalProductPrice)
				.reduce(BigDecimal.ZERO, BigDecimal::add)
				.add(allOrders.stream().map(OrderVoForTax::getOrderDiscount)
						.reduce(BigDecimal.ZERO, BigDecimal::add))
				.add(allOrders.stream().map(OrderVoForTax::getFreight)
						.reduce(BigDecimal.ZERO, BigDecimal::add))
				.add(taxFee)
				.add(serviceAmount)
				.subtract(
						allOrders.stream()
								.map(OrderVoForTax::getSellerCouponValue)
								.reduce(BigDecimal.ZERO, BigDecimal::add))
				.subtract(
						allOrders.stream()
								.map(OrderVoForTax::getSellerPromotionAmount)
								.reduce(BigDecimal.ZERO, BigDecimal::add))
				.subtract(
						allOrders.stream()
								.map(OrderVoForTax::getRegionDiscountValue)
								.reduce(BigDecimal.ZERO, BigDecimal::add))
				.setScale(2, BigDecimal.ROUND_HALF_UP);

		GetProductTaxFeeResp resp = getProductTaxFeeCall.getProductTaxFeeResp();

		if (Utils.falseIfNull(getProductTaxFeeReq.getShenqiProxyBuyOrder())) {

			Long shopId = getProductTaxFeeReq.getOrderGroups().get(0)
					.getSellerId();

			// 店主订单纯利润
			BigDecimal orderNetProfit = BigDecimal.ZERO;

			for (OrderVoForTax order : allOrders) {
				for (OrderItemVoForTax orderItem : order.getOrderItems()) {

					BigDecimal orderItemNetProfit = BigDecimal.ZERO;

					if (order.getGoodsOwnerId().compareTo(shopId) != 0) {

						BigDecimal freight = Utils.falseIfNull(orderItem
								.getFullReductionFreeFreight()) ? orderItem
								.getFreight().negate() : BigDecimal.ZERO;

						// 店主的商品纯利润
						orderItemNetProfit = orderItem
								.getOrderItemGrossProfit()
								.add(Utils.zeroIfNull(orderItem.getDiscount()))
								.add(Utils.zeroIfNull(freight))
								.subtract(
										Utils.zeroIfNull(orderItem
												.getSellerCouponValue()))
								.subtract(
										Utils.zeroIfNull(orderItem
												.getSellerPromotionValue()))
								.subtract(
										Utils.zeroIfNull(orderItem
												.getRegionDiscountValue()));
							
					} else {

						BigDecimal freight = Utils.falseIfNull(orderItem
								.getFullReductionFreeFreight()) ? BigDecimal.ZERO
								: orderItem.getFreight();

						// 店主的商品纯利润
						orderItemNetProfit = orderItem
								.getOrderItemGrossProfit()
								.add(Utils.zeroIfNull(freight))
								.add(Utils.zeroIfNull(orderItem.getDiscount()))
								.add(Utils.zeroIfNull(orderItem
										.getProdTotalTaxFee()))
								.subtract(
										Utils.zeroIfNull(orderItem
												.getSellerCouponValue()))
								.subtract(
										Utils.zeroIfNull(orderItem
												.getSellerPromotionValue()))
								.subtract(
										Utils.zeroIfNull(orderItem
												.getRegionDiscountValue()));
					}

					orderNetProfit = orderNetProfit.add(orderItemNetProfit);
				}

				if (orderNetProfit.compareTo(BigDecimal.ZERO) == -1)
					orderNetProfit = BigDecimal.ZERO;
			}

			// 使用的积分超过限额时，无法下单；这里只需要获取积分策略，计算下单使用的积分抵扣金额
			CalcOrderCreditResp calcOrderCreditResp = GodPointsService
					.calcOrderCredit(payableAmount, Utils.nullIsCNY(currency),
							shopId, getProductTaxFeeReq.getUserId());

			IntegralDeductionInfoVo expectResult = new IntegralDeductionInfoVo();

			// 积分最大抵扣金额为店主订单纯利润和积分策略中最大抵扣金额的最小值
			BigDecimal maxDeductAmount = orderNetProfit.min(calcOrderCreditResp
					.getMaxDeductAmount());

			Long maxUseIntegral = 0L;

			Long useMinLimit = (long) calcOrderCreditResp.getUseMinLimit();
			Long creditPolicy = (long) calcOrderCreditResp.getCreditPolicy();
			BigDecimal amountPolicy = calcOrderCreditResp.getAmountPolicy();
			// Long balance = (long)calcOrderCreditResp.getBalance();

			if (maxDeductAmount.compareTo(calcOrderCreditResp
					.getMaxDeductAmount()) == 0)
				maxUseIntegral = calcOrderCreditResp.getMaxUseCredit()
						.longValue();
			else {

				BigDecimal modulo = maxDeductAmount
						.divideAndRemainder(amountPolicy)[0];

				// BigDecimal creditVsAmountRate = new BigDecimal(creditPolicy)
				// .divide(amountPolicy, MathContext.DECIMAL32);

				maxUseIntegral = modulo.longValue() * (creditPolicy);

				// maxUseIntegral = new BigDecimal(maxUseIntegral).divide(
				// new BigDecimal(useMinLimit), 0, BigDecimal.ROUND_DOWN)
				// .longValue();

				// maxUseIntegral = maxUseIntegral.min(maxUseIntegral, balance);

				// if (maxUseIntegral == balance) {
				//
				// maxUseIntegral = new BigDecimal(balance).divide(
				// creditVsAmountRate, 0, BigDecimal.ROUND_DOWN)
				// .longValue();
				// }

				// maxDeductAmount = new BigDecimal(maxUseIntegral).divide(
				// creditVsAmountRate, 2, BigDecimal.ROUND_DOWN);
				maxDeductAmount = modulo.multiply(amountPolicy);
			}

			expectResult.setIntegralEnabled(calcOrderCreditResp
					.getCreditEnabled());
			expectResult.setMaxUseIntegral(maxUseIntegral);
			expectResult.setMaxDeductAmount(maxDeductAmount);
			expectResult.setIntegralBalance((long) calcOrderCreditResp
					.getBalance());
			expectResult.setIntegralPolicy((long) calcOrderCreditResp
					.getCreditPolicy());
			expectResult.setAmountPolicy(calcOrderCreditResp.getAmountPolicy());
			expectResult.setUseMinLimit(useMinLimit);
			expectResult.setOrderDeductLimit(calcOrderCreditResp
					.getOrderDeductLimit());

			this.verifyIntegralDeductionInfoVo(expectResult, resp);
		}
	}

	public void verifyIntegralDeductionInfoVo(
			IntegralDeductionInfoVo expectResult, GetProductTaxFeeResp resp) {

		Logger.comment("验证IntegralDeductionInfoVo");

		IntegralDeductionInfoVo actualResult = resp
				.getIntegralDeductionInfoVo();

		Logger.verifyEquals(expectResult.getIntegralEnabled(),
				actualResult.getIntegralEnabled(), "验证IntegralEnabled");
		DataUtil.verifyDecimalEquals(expectResult.getMaxUseIntegral(),
				actualResult.getMaxUseIntegral(), "验证MaxUseIntegral");
		DataUtil.verifyDecimalEquals(expectResult.getMaxDeductAmount(),
				actualResult.getMaxDeductAmount(), "验证MaxDeductAmount");
		DataUtil.verifyDecimalEquals(expectResult.getIntegralBalance(),
				actualResult.getIntegralBalance(), "验证IntegralBalance");
		DataUtil.verifyDecimalEquals(expectResult.getIntegralPolicy(),
				actualResult.getIntegralPolicy(), "验证IntegralPolicy");
		DataUtil.verifyDecimalEquals(expectResult.getAmountPolicy(),
				actualResult.getAmountPolicy(), "验证AmountPolicy");
		DataUtil.verifyDecimalEquals(expectResult.getUseMinLimit(),
				actualResult.getUseMinLimit(), "验证UseMinLimit");
		DataUtil.verifyDecimalEquals(expectResult.getOrderDeductLimit(),
				actualResult.getOrderDeductLimit(), "验证OrderDeductLimit");
	}

	private static HashMap<String, BigDecimal> calcExpectedOrderTaxFee(
			List<OrderVoForTax> orders, BigDecimal serviceRate) {

		int scale = 2;
		
		BigDecimal orderTaxFee = BigDecimal.ZERO;
		BigDecimal orderServiceAmount = BigDecimal.ZERO;
		BigDecimal orderRegionDiscountAmount = BigDecimal.ZERO;

		for (OrderVoForTax o : orders) {

			BigDecimal productTaxFee = BigDecimal.ZERO;
			BigDecimal productServiceFee = BigDecimal.ZERO;

			for (OrderItemVoForTax orderItem : o.getOrderItems()) {

				if (null == getProductTaxFeeReq.getCurrency())
					scale = 2;
				else if (null != getProductTaxFeeReq.getCurrency()
						&& getProductTaxFeeReq.getCurrency().equalsIgnoreCase(
								"JPY"))
					scale = 0;

				if (SqTradingCallService
						.isFreePerimeters(getProductTaxFeeReq.getAddress())) {
					productTaxFee = BigDecimal.ZERO;
				} else {

					productTaxFee = Utils
							.zeroIfNull(
									Utils.falseIfNull(orderItem
											.getFullReductionFreeFreight()) ? BigDecimal.ZERO
											: orderItem.getFreight())
							.divide(new BigDecimal(orderItem.getProductNum()), 2,
									BigDecimal.ROUND_UP)
							.add(orderItem.getProductPrice())
							.add(Utils.zeroIfNull(orderItem.getDiscount()).divide(
									new BigDecimal(orderItem.getProductNum()), 2,
									BigDecimal.ROUND_UP))
							.subtract(
									Utils.zeroIfNull(
											orderItem.getSellerCouponValue())
											.divide(new BigDecimal(orderItem
															.getProductNum()), 2,
													BigDecimal.ROUND_UP))
							.subtract(
									Utils.zeroIfNull(
											orderItem.getSellerPromotionValue())
											.divide(new BigDecimal(orderItem
															.getProductNum()), 2,
													BigDecimal.ROUND_UP))
							.subtract(
									Utils.zeroIfNull(
											orderItem.getRegionDiscountValue())
											.divide(new BigDecimal(orderItem
															.getProductNum()), 2,
													BigDecimal.ROUND_UP))
							.multiply(Utils.zeroIfNull(orderItem.getProdTaxRate()))
							.setScale(scale, BigDecimal.ROUND_HALF_UP);
				}

				BigDecimal prodTotalTaxFee = productTaxFee
						.multiply(new BigDecimal(orderItem.getProductNum()));
				orderItem.setProdTotalTaxFee(prodTotalTaxFee);

				if (null != serviceRate) {

					productServiceFee = orderItem
							.getProductPrice()
							.multiply(new BigDecimal(orderItem.getProductNum()))
							.add(Utils.zeroIfNull(orderItem.getDiscount()))
							.add(Utils.falseIfNull(orderItem
									.getFullReductionFreeFreight()) ? BigDecimal.ZERO
									: orderItem.getFreight())
							.subtract(
									Utils.zeroIfNull(orderItem
											.getSellerCouponValue()))
							.subtract(
									Utils.zeroIfNull(orderItem
											.getSellerPromotionValue()))
							.subtract(
									Utils.zeroIfNull(orderItem
											.getRegionDiscountValue()))
							.add(productTaxFee.multiply(new BigDecimal(
									orderItem.getProductNum())))
							.multiply(serviceRate)
							.multiply(new BigDecimal("0.01"))
							.setScale(scale, BigDecimal.ROUND_HALF_UP);
				}

				orderTaxFee = orderTaxFee.add(prodTotalTaxFee);
				orderServiceAmount = orderServiceAmount.add(productServiceFee);
				orderRegionDiscountAmount = orderRegionDiscountAmount.add(Utils
						.zeroIfNull(orderItem.getRegionDiscountValue()));
			}
		}

		HashMap<String, BigDecimal> map = new HashMap<>();

		map.put("orderTaxFee", orderTaxFee);
		map.put("orderServiceAmount", orderServiceAmount);
		map.put("regionDiscountAmount", orderRegionDiscountAmount);

		return map;
	}

	/**
	 * 分摊平台折扣到订单
	 * 
	 * @param orders
	 * @param discountValue
	 * @param orderWeights
	 */
	private static void apportionOrderDiscountToOrder(
			List<OrderVoForTax> orders, BigDecimal discountValue,
			List<BigDecimal> orderWeights, String currency, boolean isNegate) {

		List<BigDecimal> maxLimits = new ArrayList<BigDecimal>();

		for (OrderVoForTax o : orders) {
			maxLimits.add(o.calcMaxPromotionLeftAndFreight());
		}

		BigDecimal[] result = Utils.apportionByWeightsAndMaxLimit(
				discountValue.abs(), orderWeights.toArray(new BigDecimal[0]),
				maxLimits.toArray(new BigDecimal[0]), currency);

		for (int i = 0; i < result.length; i++) {
			orders.get(i).setOrderDiscount(isNegate ? result[i].negate() : result[i]);
		}
	}

	/**
	 * 分摊平台折扣到订单商品
	 * 
	 * @param orders
	 */
	private static void apportionOrderDiscountToOrderItem(
			List<OrderVoForTax> orders, String currency, boolean isNegate) {

		for (OrderVoForTax order : orders) {
			BigDecimal[] result = Utils.apportionByWeights3(order
					.getOrderDiscount().abs(), order.getOrderItemWeightsOnDiscount()
					.toArray(new BigDecimal[0]), currency);

			for (int i = 0; i < result.length; i++) {
				order.getOrderItems().get(i).setDiscount(isNegate ? result[i].negate() : result[i]);
			}
		}
	}

	/**
	 * 分摊商家优惠
	 *
	 * @param group
	 */
	private static void apportionSellerPromotions(OrderGroupVoForTax group) {
		if (!CollectionUtils.isEmpty(group.getSellerPromotionApportions())) {
			group.distributeSellerPromotionApportions();
		}
	}

	/**
	 * 分摊商家优惠券到订单
	 */
	private static void apportionSellerCouponToOrder(OrderGroupVoForTax g,
			String currency, CouponVo sellerCouponVo, int index) {
		
		Logger.comment(String.format("分摊第%s张优惠券到订单", index + 1));
		
		if (sellerCouponVo.getCouponType() == 5) {

			BigDecimal[] couponValues = g.getOrderWeightsOnSellerCoupon()
					.toArray(new BigDecimal[0]);

			for (int i = 0; i < couponValues.length; i++) {

				g.getOrders().get(i).setSellerCouponValue(couponValues[i]);

				OrderCouponDetailPo orderCouponDetailPo = new OrderCouponDetailPo();

				orderCouponDetailPo.setCouponCode(sellerCouponVo
						.getCouponCode());
				orderCouponDetailPo.setCouponSource(sellerCouponVo
						.getCouponSource());
				orderCouponDetailPo.setCouponType(5);
				orderCouponDetailPo.setDeleted(false);
				orderCouponDetailPo.setAmount(couponValues[i]);
			}
		} else {

			BigDecimal[] result = Utils.apportionByWeights3(sellerCouponVo
					.getCouponValue(), g.getOrderWeightsOnSellerCoupon()
					.toArray(new BigDecimal[0]), currency);
			
			List<BigDecimal> newOrderWeightsOnSellerCoupon = new ArrayList<>();

			for (int i = 0; i < result.length; i++) {
				
				g.getOrders()
						.get(i)
						.setSellerCouponValue(
								Utils.zeroIfNull(
										g.getOrders().get(i)
												.getSellerCouponValue()).add(
										result[i]));
				
				OrderCouponDetailPo orderCouponDetailPo = new OrderCouponDetailPo();

				orderCouponDetailPo.setCouponCode(sellerCouponVo
						.getCouponCode());
				orderCouponDetailPo.setCouponSource(sellerCouponVo
						.getCouponSource());
				orderCouponDetailPo.setCouponType(sellerCouponVo.getCouponType());
				orderCouponDetailPo.setDeleted(false);
				orderCouponDetailPo.setAmount(result[i]);
				
				newOrderWeightsOnSellerCoupon.add(g
						.getOrderWeightsOnSellerCoupon().get(i)
						.subtract(result[i]));
			}
			
			g.setOrderWeightsOnSellerCoupon(newOrderWeightsOnSellerCoupon);
		}
	}

	/**
	 * 分摊商家优惠券到订单商品
	 * 
	 * @param g
	 */
	private static void apportionSellerCouponToOrderItem(OrderGroupVoForTax g,
			String currency, int index) {
		
		Logger.comment(String.format("分摊第%s张优惠券到商品项", index + 1));

		for (OrderVoForTax order : g.getOrders()) {
			if (order.getSellerCouponCode() != null) {

				if (order.getSellerCouponType() == 5) {

					for (int i = 0; i < order.getOrderItems().size(); i++) {

						if (order.getOrderItems().get(i).getCatalogId()
								.startsWith("speeccc"))
							order.getOrderItems()
									.get(i)
									.setSellerCouponValue(
											order.getOrderItems().get(i)
													.getProductPrice());
					}
				} else {

					BigDecimal[] result = Utils.apportionByWeights3(
							order.getSellerCouponValue(),
							order.getOrderItemWeightsOnSellerCoupon().toArray(
									new BigDecimal[0]), currency);
					for (int i = 0; i < result.length; i++) {
						order.getOrderItems().get(i)
								.setSellerCouponValue(result[i]);
					}
				}
			}
		}
	}
	
	/**
	 * 计算区域折扣到订单
	 */
	private static void calcRegionDiscountToOrder(OrderGroupVoForTax g,
			String currency) {
		
		// 订单上区域折扣权重
		for (OrderVoForTax order : g.getOrders()) {

			// 区域折扣金额
			if (Utils.zeroIfNull(order.getRegionDiscountRatio())
					.compareTo(BigDecimal.ZERO) == 1) {

				BigDecimal regionDiscountRate = BigDecimal.ONE.subtract(Utils
						.zeroIfNull(order.getRegionDiscountRatio())
						.divide(BigDecimal.TEN, 4, BigDecimal.ROUND_DOWN));

				BigDecimal regionDiscount = order.getTotalProductPrice()
						.subtract(order.getSellerPromotionAmount()).multiply(
								regionDiscountRate).setScale(2, BigDecimal.ROUND_DOWN);

				order.setRegionDiscountValue(regionDiscount);
			} else
				order.setRegionDiscountValue(BigDecimal.ZERO);
		}
	}

	/**
	 * 分摊区域折扣到订单商品
	 * 
	 * @param g
	 */
	private static void apportionRegionDiscountToOrderItem(OrderGroupVoForTax g,
			String currency) {

		for (OrderVoForTax order : g.getOrders()) {
			
			// 订单项上区域折扣权重
			for (OrderItemVoForTax orderItem : order.getOrderItems()) {

				order.getOrderItemWeightsOnRegionDiscount().add(
						orderItem
								.getProductPrice()
								.multiply(
										new BigDecimal(orderItem
												.getProductNum()))
								.subtract(
										Utils.zeroIfNull(orderItem
												.getSellerPromotionValue())));
			}
			
			if (Utils.zeroIfNull(order.getRegionDiscountValue()).compareTo(BigDecimal.ZERO) == 1) {
				BigDecimal[] result = Utils.apportionByWeights3(
						order.getRegionDiscountValue(),
						order.getOrderItemWeightsOnRegionDiscount().toArray(
								new BigDecimal[0]), currency);
				for (int i = 0; i < result.length; i++) {
					order.getOrderItems().get(i)
							.setRegionDiscountValue(result[i]);
				}
			}
		}
	}
	
	/**
	 * 分摊CDF优惠券到订单商品
	 *
	 */
	private static void apportionCDFCouponToOrderItem(
			List<OrderItemVoForTax> orderItemList, List<CouponAmountVo> couponAmountList) {

		for (int i = 0; i < couponAmountList.size(); i++) {

			orderItemList.get(i).setSellerCouponValue(
					couponAmountList.get(i).getDeductionAmount());
		}
	}

	private static boolean couponApplicable(OrderItemVoForTax orderItem,
			CouponVo coupon) {
		switch (coupon.getApplianceType()) {
		case ALL:
			return true;
		case SPEC_RODUCT:
			return coupon.getApplianceTargets().contains(
					orderItem.getProductId());
		default:
			throw new IllegalArgumentException("未知的优惠券适用类型:"
					+ coupon.getApplianceType());
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetProductTaxFee_001() {
		Logger.start(true, "单个商品，获得税费");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 2, false);

			getProductTaxFeeReq = buildStandGetProductTaxFeeReq(productBean,
					autotest_goodsOwnerId, new BigDecimal("0.15"));

			getProductTaxFeeCall.setData(getProductTaxFeeReq);
			getProductTaxFeeCall.callService();

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetProductTaxFee_002() {
		Logger.start(true, "单个订单，多个商品，获得税费");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);

			getProductTaxFeeReq = buildStandGetProductTaxFeeReq(productBean,
					autotest_goodsOwnerId, new BigDecimal("0.23059"));

			// 创建另一个商品
			OrderItemVoForTax orderItemVoForTax = new OrderItemVoForTax();

			orderItemVoForTax.setCatalogId(productBean.getCatalogList().get(1));
			orderItemVoForTax.setFreight(new BigDecimal(new Random()
					.nextInt(20) + 10));
			orderItemVoForTax.setProdTaxRate(new BigDecimal("0.12"));
			orderItemVoForTax.setProductId(productBean.getProductId());
			orderItemVoForTax.setProductNum(new Random().nextInt(4) + 2);
			orderItemVoForTax.setProductPrice(new BigDecimal(new Random()
					.nextInt(50) + 1542));

			getProductTaxFeeReq.getOrderGroups().get(0).getOrders().get(0)
					.getOrderItems().add(orderItemVoForTax);

			getProductTaxFeeCall.setData(getProductTaxFeeReq);
			getProductTaxFeeCall.callService();

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetProductTaxFee_003() {
		Logger.start(true, "多个订单，多个商品，获得税费");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 2, false);

			getProductTaxFeeReq = buildStandGetProductTaxFeeReq(productBean,
					autotest_goodsOwnerId, new BigDecimal("0.15"));

			// 创建另一个商品
			OrderItemVoForTax orderItemVoForTax = new OrderItemVoForTax();

			orderItemVoForTax.setCatalogId(productBean.getCatalogList().get(1));
			orderItemVoForTax.setFreight(new BigDecimal(new Random()
					.nextInt(20) + 10));
			orderItemVoForTax.setProdTaxRate(new BigDecimal("0.12"));
			orderItemVoForTax.setProductId(productBean.getProductId());
			orderItemVoForTax.setProductNum(new Random().nextInt(4) + 2);
			orderItemVoForTax.setProductPrice(new BigDecimal(new Random()
					.nextInt(50) + 1542));

			// 创建另一个订单
			OrderVoForTax orderVoForTax = new OrderVoForTax();

			orderVoForTax.setGoodsOwnerId(autotest_goodsOwnerId);
			orderVoForTax.setOrderItems(Lists.newArrayList(orderItemVoForTax));

			getProductTaxFeeReq.getOrderGroups().get(0).getOrders()
					.add(orderVoForTax);

			getProductTaxFeeReq.setDiscount(BigDecimal.TEN.negate());

			getProductTaxFeeCall.setData(getProductTaxFeeReq);
			getProductTaxFeeCall.callService();

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetProductTaxFee_004() {
		Logger.start(true, "多个订单组，多个商品，查询报错");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);

			getProductTaxFeeReq = buildStandGetProductTaxFeeReq(productBean,
					autotest_goodsOwnerId, new BigDecimal("0.15"));

			// 创建另一个商品
			OrderItemVoForTax orderItemVoForTax = new OrderItemVoForTax();

			orderItemVoForTax.setCatalogId(productBean.getCatalogList().get(1));
			orderItemVoForTax.setFreight(new BigDecimal(new Random()
					.nextInt(20) + 10));
			orderItemVoForTax.setProdTaxRate(new BigDecimal("0.06"));
			orderItemVoForTax.setProductId(productBean.getProductId());
			orderItemVoForTax.setProductNum(new Random().nextInt(4) + 2);
			orderItemVoForTax.setProductPrice(new BigDecimal("633.00"));

			// 创建另一个订单
			OrderVoForTax orderVoForTax = new OrderVoForTax();

			orderVoForTax.setGoodsOwnerId(autotest_goodsOwnerId);
			orderVoForTax.setOrderItems(Lists.newArrayList(orderItemVoForTax));

			// 创建另一个订单组
			OrderGroupVoForTax orderGroupVoForTax = new OrderGroupVoForTax();

			orderGroupVoForTax.setSellerId(productBean.getSellerId());
			orderGroupVoForTax.setOrders(Lists.newArrayList(orderVoForTax));

			getProductTaxFeeReq.getOrderGroups().add(orderGroupVoForTax);

			getProductTaxFeeReq.setDiscount(BigDecimal.TEN.negate());

			getProductTaxFeeCall.setData(getProductTaxFeeReq);
			getProductTaxFeeCall.callService();

			Logger.verifyEquals(400, getProductTaxFeeCall.getCode(), "验证code");
			Logger.verifyEquals(100, getProductTaxFeeCall.getBcode(), "验证bcode");
			Logger.verifyEquals("不能有来自多个店铺的订单", getProductTaxFeeCall.getMsg(),
					"验证msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetProductTaxFee_005() {
		Logger.start(true, "单个订单，多个商品，包含买手优惠券和买手促销，获得税费");
		try {

			Integer mchId = DGSQBaseService.createIndependenceMch("USA");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createIndependenceProxychain(mchId, 1, false, false);

			getProductTaxFeeReq = buildStandGetProductTaxFeeReq(productBean,
					(long) mchId, new BigDecimal("0.15"), true);

			OrderItemVoForTax orderItemVoForTax1 = getProductTaxFeeReq
					.getOrderGroups().get(0).getOrders().get(0).getOrderItems()
					.get(0);

			// 创建另一个商品
			OrderItemVoForTax orderItemVoForTax2 = new OrderItemVoForTax();

			orderItemVoForTax2
					.setCatalogId(productBean.getCatalogList().get(1));
			orderItemVoForTax2.setFreight(new BigDecimal(new Random()
					.nextInt(20) + 10));
			orderItemVoForTax2.setProdTaxRate(new BigDecimal("0.12"));
			orderItemVoForTax2.setProductId(productBean.getProductId());
			orderItemVoForTax2.setProductNum(1);
			orderItemVoForTax2.setProductPrice(new BigDecimal("1542.00"));

			getProductTaxFeeReq.getOrderGroups().get(0).getOrders().get(0)
					.getOrderItems().add(orderItemVoForTax2);

			// 定义买手下的优惠商品信息list
			List<SellerPromotionVo> sellerPromotionList = new ArrayList<SellerPromotionVo>();

			SellerPromotionVo sellerPromotion1 = new SellerPromotionVo();

			sellerPromotion1.setAmountCondition(new BigDecimal(100));
			sellerPromotion1.setId(123456789);
			sellerPromotion1.setName("自动化商家优惠活动");

			sellerPromotion1.setPromotionValue(new BigDecimal(12));
			sellerPromotion1.setQtyCondition(4);

			sellerPromotion1.setReducedAmount(new BigDecimal(15));
			sellerPromotion1.setType(PromotionTypeEnum.ReduceIfAmountEnough);

			sellerPromotion1.setApportions(Arrays.asList(
					new CatalogApportionVo(orderItemVoForTax1.getCatalogId(),
							orderItemVoForTax1.getProductNum()),
					new CatalogApportionVo(orderItemVoForTax2.getCatalogId(),
							orderItemVoForTax2.getProductNum())));

			sellerPromotionList.add(sellerPromotion1);

			getProductTaxFeeReq.getOrderGroups().get(0)
					.setSellerPromotionApportions(sellerPromotionList);

			getProductTaxFeeReq.setDiscount(BigDecimal.ZERO);

			getProductTaxFeeCall.setData(getProductTaxFeeReq);
			getProductTaxFeeCall.callService();

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetProductTaxFee_006() {
		Logger.start(true, "单个订单，多个商品，日本代理， 获得税费");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createJPProxychain(500058147, 2, false, true);

			getProductTaxFeeReq = buildStandGetProductTaxFeeReq(productBean,
					500058147L, new BigDecimal("0.15"));

			// 创建另一个商品
			OrderItemVoForTax orderItemVoForTax = new OrderItemVoForTax();

			orderItemVoForTax.setCatalogId(productBean.getCatalogList().get(1));
			orderItemVoForTax.setFreight(new BigDecimal(new Random()
					.nextInt(20) + 10));
			orderItemVoForTax.setProdTaxRate(new BigDecimal("0.12"));
			orderItemVoForTax.setProductId(productBean.getProductId());
			orderItemVoForTax.setProductNum(new Random().nextInt(4) + 2);
			orderItemVoForTax.setProductPrice(new BigDecimal(new Random()
					.nextInt(50) + 1542));

			getProductTaxFeeReq.getOrderGroups().get(0).getOrders().get(0)
					.getOrderItems().add(orderItemVoForTax);

			getProductTaxFeeCall.setData(getProductTaxFeeReq);
			getProductTaxFeeCall.callService();

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetProductTaxFee_007() {
		Logger.start(true, "单个商品，无折扣，获得税费");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 2, false);

			getProductTaxFeeReq = buildStandGetProductTaxFeeReq(productBean,
					autotest_goodsOwnerId, new BigDecimal("0.15"));

			getProductTaxFeeReq.setDiscount(BigDecimal.ZERO);

			getProductTaxFeeCall.setData(getProductTaxFeeReq);
			getProductTaxFeeCall.callService();

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetProductTaxFee_008() {
		Logger.start(true, "单个商品，非神器订单，获得税费");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false);

			getProductTaxFeeReq = buildStandGetProductTaxFeeReq(productBean,
					autotest_goodsOwnerId, new BigDecimal("0.15"));

			getProductTaxFeeReq.setFromShenqi(false);

			getProductTaxFeeCall.setData(getProductTaxFeeReq);
			getProductTaxFeeCall.callService();

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetProductTaxFee_009() {
		Logger.start(true, "单个商品，免运费，获得税费");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 2, false);

			getProductTaxFeeReq = buildStandGetProductTaxFeeReq(productBean,
					autotest_goodsOwnerId, new BigDecimal("0.15"));

			getProductTaxFeeReq.setDiscount(BigDecimal.ZERO);

			getProductTaxFeeReq.getOrderGroups().get(0).getOrders().get(0)
					.getOrderItems().get(0).setFullReductionFreeFreight(true);

			getProductTaxFeeCall.setData(getProductTaxFeeReq);
			getProductTaxFeeCall.callService();

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetProductTaxFee_010() {
		Logger.start(true, "单个商品，如果地址为免税区，则税费为0");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 2, false);

			getProductTaxFeeReq = buildStandGetProductTaxFeeReq(productBean,
					autotest_goodsOwnerId, new BigDecimal("0.15"));

			getProductTaxFeeReq.setDiscount(BigDecimal.ZERO);
			getProductTaxFeeReq.setAddress("澳门" + TestDataManager.randomStr(7));

			getProductTaxFeeCall.setData(getProductTaxFeeReq);
			getProductTaxFeeCall.callService();

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetProductTaxFee_011() {
		Logger.start(true, "单个订单，多个商品，包含买手优惠券和买手促销，设置服务费率，获得税费和服务费");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false);

			getProductTaxFeeReq = buildStandGetProductTaxFeeReq(productBean,
					(long) autotest_goodsOwnerId, new BigDecimal("0.15"), true);

			getProductTaxFeeReq.getOrderGroups().get(0)
					.setServiceRate(new BigDecimal("7.00"));

			OrderItemVoForTax orderItemVoForTax1 = getProductTaxFeeReq
					.getOrderGroups().get(0).getOrders().get(0).getOrderItems()
					.get(0);

			// 创建另一个商品
			OrderItemVoForTax orderItemVoForTax2 = new OrderItemVoForTax();

			orderItemVoForTax2
					.setCatalogId(productBean.getCatalogList().get(1));
			orderItemVoForTax2.setFreight(new BigDecimal(new Random()
					.nextInt(20) + 10));
			orderItemVoForTax2.setProdTaxRate(new BigDecimal("0.12"));
			orderItemVoForTax2.setProductId(productBean.getProductId());
			orderItemVoForTax2.setProductNum(1);
			orderItemVoForTax2.setProductPrice(new BigDecimal("1542.00"));

			getProductTaxFeeReq.getOrderGroups().get(0).getOrders().get(0)
					.getOrderItems().add(orderItemVoForTax2);

			// 定义买手下的优惠商品信息list
			List<SellerPromotionVo> sellerPromotionList = new ArrayList<SellerPromotionVo>();

			SellerPromotionVo sellerPromotion1 = new SellerPromotionVo();

			sellerPromotion1.setAmountCondition(new BigDecimal(100));
			sellerPromotion1.setId(123456789);
			sellerPromotion1.setName("自动化商家优惠活动");

			sellerPromotion1.setPromotionValue(new BigDecimal(12));
			sellerPromotion1.setQtyCondition(4);

			sellerPromotion1.setReducedAmount(new BigDecimal(15));
			sellerPromotion1.setType(PromotionTypeEnum.ReduceIfAmountEnough);

			sellerPromotion1.setApportions(Arrays.asList(
					new CatalogApportionVo(orderItemVoForTax1.getCatalogId(),
							orderItemVoForTax1.getProductNum()),
					new CatalogApportionVo(orderItemVoForTax2.getCatalogId(),
							orderItemVoForTax2.getProductNum())));

			sellerPromotionList.add(sellerPromotion1);

			getProductTaxFeeReq.getOrderGroups().get(0)
					.setSellerPromotionApportions(sellerPromotionList);

			getProductTaxFeeReq.setDiscount(BigDecimal.ZERO);

			getProductTaxFeeCall.setData(getProductTaxFeeReq);
			getProductTaxFeeCall.callService();

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetProductTaxFee_012() {
		Logger.start(true, "代理订单订单，单个商品，设置服务费率，无法获得服务费");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 2, false);

			getProductTaxFeeReq = buildStandGetProductTaxFeeReq(productBean,
					autotest_goodsOwnerId, new BigDecimal("0.15"));

			getProductTaxFeeReq.getOrderGroups().get(0)
					.setServiceRate(new BigDecimal("11.00"));

			getProductTaxFeeCall.setData(getProductTaxFeeReq);
			getProductTaxFeeCall.callService();

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetProductTaxFee_013() {
		Logger.start(true, "单个订单，多个商品，日本代理， 获得税费");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createJPProxychain(500058147, 0, false, true);

			getProductTaxFeeReq = buildStandGetProductTaxFeeReq(productBean,
					500058147L, new BigDecimal("0.15"));

			// 创建另一个商品
			OrderItemVoForTax orderItemVoForTax = new OrderItemVoForTax();

			orderItemVoForTax.setCatalogId(productBean.getCatalogList().get(1));
			orderItemVoForTax.setFreight(new BigDecimal(new Random()
					.nextInt(20) + 10));
			orderItemVoForTax.setProdTaxRate(new BigDecimal("0.12"));
			orderItemVoForTax.setProductId(productBean.getProductId());
			orderItemVoForTax.setProductNum(new Random().nextInt(4) + 2);
			orderItemVoForTax.setProductPrice(new BigDecimal(new Random()
					.nextInt(50) + 1542));

			getProductTaxFeeReq.getOrderGroups().get(0).getOrders().get(0)
					.getOrderItems().add(orderItemVoForTax);
			getProductTaxFeeReq.getOrderGroups().get(0)
					.setServiceRate(new BigDecimal("3.12"));

			getProductTaxFeeCall.setData(getProductTaxFeeReq);
			getProductTaxFeeCall.callService();

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetProductTaxFee_014() {
		Logger.start(true, "单个订单，直销商，多个商品，包含买手优惠券和买手促销，获得税费，买家可用积分");
		try {

			Integer mchId = DGSQBaseService.createIndependenceMch("USA");

			GodPointsService.saveCreditPolicyReq((long) mchId);
			Thread.sleep(500);

			GodPointsService.sendCredit((long) mchId, 20238699L);
			Thread.sleep(500);

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createIndependenceProxychain(mchId, 0, false, false);

			getProductTaxFeeReq = buildStandGetProductTaxFeeReq(productBean,
					(long) mchId, new BigDecimal("0.15"), true);

			OrderItemVoForTax orderItemVoForTax1 = getProductTaxFeeReq
					.getOrderGroups().get(0).getOrders().get(0).getOrderItems()
					.get(0);

			// 创建另一个商品
			OrderItemVoForTax orderItemVoForTax2 = new OrderItemVoForTax();

			orderItemVoForTax2
					.setCatalogId(productBean.getCatalogList().get(1));
			orderItemVoForTax2.setFreight(new BigDecimal(new Random()
					.nextInt(20) + 10));
			orderItemVoForTax2.setProdTaxRate(new BigDecimal("0.12"));
			orderItemVoForTax2.setProductId(productBean.getProductId());
			orderItemVoForTax2.setProductNum(1);
			orderItemVoForTax2.setProductPrice(new BigDecimal("1542.00"));

			getProductTaxFeeReq.getOrderGroups().get(0).getOrders().get(0)
					.getOrderItems().add(orderItemVoForTax2);

			// 定义买手下的优惠商品信息list
			List<SellerPromotionVo> sellerPromotionList = new ArrayList<SellerPromotionVo>();

			SellerPromotionVo sellerPromotion1 = new SellerPromotionVo();

			sellerPromotion1.setAmountCondition(new BigDecimal(100));
			sellerPromotion1.setId(123456789);
			sellerPromotion1.setName("自动化商家优惠活动");

			sellerPromotion1.setPromotionValue(new BigDecimal(12));
			sellerPromotion1.setQtyCondition(4);

			sellerPromotion1.setReducedAmount(new BigDecimal(15));
			sellerPromotion1.setType(PromotionTypeEnum.ReduceIfAmountEnough);

			sellerPromotion1.setApportions(Arrays.asList(
					new CatalogApportionVo(orderItemVoForTax1.getCatalogId(),
							orderItemVoForTax1.getProductNum()),
					new CatalogApportionVo(orderItemVoForTax2.getCatalogId(),
							orderItemVoForTax2.getProductNum())));

			sellerPromotionList.add(sellerPromotion1);

			getProductTaxFeeReq.getOrderGroups().get(0)
					.setSellerPromotionApportions(sellerPromotionList);

			getProductTaxFeeReq.setDiscount(BigDecimal.ZERO);
			getProductTaxFeeReq.setShenqiProxyBuyOrder(true);
			getProductTaxFeeReq.setFreeShipAndTax(false);

			getProductTaxFeeCall.setData(getProductTaxFeeReq);
			getProductTaxFeeCall.callService();

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetProductTaxFee_015() {
		Logger.start(true, "单个订单，代理订单，多个商品，包含买手优惠券和买手促销，获得税费，买家可用积分");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);

			Long shopId = productBean.getSellerId();

			GodPointsService.saveCreditPolicyReq((long) shopId);
			Thread.sleep(500);

			GodPointsService.sendCredit((long) shopId, 20238699L);
			Thread.sleep(500);

			getProductTaxFeeReq = buildStandGetProductTaxFeeReq(productBean,
					(long) autotest_goodsOwnerId, new BigDecimal("0.15"), true);

			OrderItemVoForTax orderItemVoForTax1 = getProductTaxFeeReq
					.getOrderGroups().get(0).getOrders().get(0).getOrderItems()
					.get(0);

			// 创建另一个商品
			OrderItemVoForTax orderItemVoForTax2 = new OrderItemVoForTax();

			orderItemVoForTax2
					.setCatalogId(productBean.getCatalogList().get(1));
			orderItemVoForTax2.setFreight(new BigDecimal(new Random()
					.nextInt(20) + 10));
			orderItemVoForTax2.setProdTaxRate(new BigDecimal("0.12"));
			orderItemVoForTax2.setProductId(productBean.getProductId());
			orderItemVoForTax2.setProductNum(1);
			orderItemVoForTax2.setProductPrice(new BigDecimal("1542.00"));

			getProductTaxFeeReq.getOrderGroups().get(0).getOrders().get(0)
					.getOrderItems().add(orderItemVoForTax2);

			// 定义买手下的优惠商品信息list
			List<SellerPromotionVo> sellerPromotionList = new ArrayList<SellerPromotionVo>();

			SellerPromotionVo sellerPromotion1 = new SellerPromotionVo();

			sellerPromotion1.setAmountCondition(new BigDecimal(100));
			sellerPromotion1.setId(123456789);
			sellerPromotion1.setName("自动化商家优惠活动");

			sellerPromotion1.setPromotionValue(new BigDecimal(12));
			sellerPromotion1.setQtyCondition(4);

			sellerPromotion1.setReducedAmount(new BigDecimal(15));
			sellerPromotion1.setType(PromotionTypeEnum.ReduceIfAmountEnough);

			sellerPromotion1.setApportions(Arrays.asList(
					new CatalogApportionVo(orderItemVoForTax1.getCatalogId(),
							orderItemVoForTax1.getProductNum()),
					new CatalogApportionVo(orderItemVoForTax2.getCatalogId(),
							orderItemVoForTax2.getProductNum())));

			sellerPromotionList.add(sellerPromotion1);

			getProductTaxFeeReq.getOrderGroups().get(0)
					.setSellerPromotionApportions(sellerPromotionList);

			getProductTaxFeeReq.setDiscount(BigDecimal.ZERO);
			getProductTaxFeeReq.setShenqiProxyBuyOrder(true);
			getProductTaxFeeReq.setFreeShipAndTax(false);

			getProductTaxFeeCall.setData(getProductTaxFeeReq);
			getProductTaxFeeCall.callService();

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetProductTaxFee_016() {
		Logger.start(true, "单个订单，单商品，直销商，买家可用积分, 店主利润为0");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);

			Long shopId = productBean.getSellerId();

			GodPointsService.saveCreditPolicyReq((long) shopId);
			Thread.sleep(500);

			GodPointsService.sendCredit((long) shopId, 20238699L);
			Thread.sleep(500);

			getProductTaxFeeReq = buildStandGetProductTaxFeeReq(productBean,
					(long) autotest_goodsOwnerId, null, false);

			OrderItemVoForTax orderItemVoForTax1 = getProductTaxFeeReq
					.getOrderGroups().get(0).getOrders().get(0).getOrderItems()
					.get(0);

			orderItemVoForTax1.setProductPrice(new BigDecimal(productBean
					.getAgentCatalogPriceList().get(0).getDirectPrice()));
			orderItemVoForTax1.setFreight(BigDecimal.ZERO);

			getProductTaxFeeReq.setDiscount(BigDecimal.ZERO);
			getProductTaxFeeReq.setShenqiProxyBuyOrder(true);
			getProductTaxFeeReq.setFreeShipAndTax(false);

			getProductTaxFeeCall.setData(getProductTaxFeeReq);
			getProductTaxFeeCall.callService();

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetProductTaxFee_017() {
		Logger.start(true, "单个订单，单商品，代理商，买家可用积分, 店主利润不足积分策略的最大抵扣");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);

			Long shopId = productBean.getSellerId();

			GodPointsService.saveCreditPolicyReq((long) shopId);
			Thread.sleep(500);

			GodPointsService.sendCredit((long) shopId, 20238699L);
			Thread.sleep(500);

			getProductTaxFeeReq = buildStandGetProductTaxFeeReq(productBean,
					(long) autotest_goodsOwnerId, null, false);

			OrderItemVoForTax orderItemVoForTax1 = getProductTaxFeeReq
					.getOrderGroups().get(0).getOrders().get(0).getOrderItems()
					.get(0);

			orderItemVoForTax1.setProductPrice(new BigDecimal(productBean
					.getAgentCatalogPriceList().get(0).getDirectPrice())
					.add(BigDecimal.TEN));
			orderItemVoForTax1.setFreight(BigDecimal.ZERO);

			getProductTaxFeeReq.setDiscount(BigDecimal.ZERO);
			getProductTaxFeeReq.setShenqiProxyBuyOrder(true);
			getProductTaxFeeReq.setFreeShipAndTax(false);

			getProductTaxFeeCall.setData(getProductTaxFeeReq);
			getProductTaxFeeCall.callService();

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetProductTaxFee_018() {
		Logger.start(true, "单个订单，单商品，代理商，买家可用积分, 店主利润不足积分策略的最大抵扣且积分余额小于店主利润");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);

			Long shopId = productBean.getSellerId();

			CreditPolicy creditPolicy_SHARE_SEND = new CreditPolicy();

			creditPolicy_SHARE_SEND.setAmount(BigDecimal.TEN);
			creditPolicy_SHARE_SEND.setBizType(PointsBizTypeEnum.SHARE_SEND
					.getCode());
			creditPolicy_SHARE_SEND.setCredit(10);
			creditPolicy_SHARE_SEND.setCurrency("");

			GodPointsService.saveCreditPolicyReqWithSHARE_SEND((long) shopId,
					creditPolicy_SHARE_SEND);
			Thread.sleep(500);

			GodPointsService.sendCredit((long) shopId, 20238699L);
			Thread.sleep(500);

			getProductTaxFeeReq = buildStandGetProductTaxFeeReq(productBean,
					(long) autotest_goodsOwnerId, null, false);

			OrderItemVoForTax orderItemVoForTax1 = getProductTaxFeeReq
					.getOrderGroups().get(0).getOrders().get(0).getOrderItems()
					.get(0);

			orderItemVoForTax1.setProductPrice(new BigDecimal(productBean
					.getAgentCatalogPriceList().get(0).getDirectPrice())
					.add(new BigDecimal("500.00")));
			orderItemVoForTax1.setFreight(BigDecimal.ZERO);
			orderItemVoForTax1.setProductNum(1);

			getProductTaxFeeReq.setDiscount(BigDecimal.ZERO);
			getProductTaxFeeReq.setShenqiProxyBuyOrder(true);
			getProductTaxFeeReq.setFreeShipAndTax(false);

			getProductTaxFeeCall.setData(getProductTaxFeeReq);
			getProductTaxFeeCall.callService();

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetProductTaxFee_019() {
		Logger.start(true, "单个订单，代理订单，多个商品，包含买手优惠券、区域折扣和买手促销，获得税费，买家可用积分");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);

			Long shopId = productBean.getSellerId();

			CreditPolicy creditPolicy_ORDER_DEDUCT = new CreditPolicy();

			creditPolicy_ORDER_DEDUCT.setAmount(BigDecimal.TEN);
			creditPolicy_ORDER_DEDUCT.setBizType(PointsBizTypeEnum.ORDER_DEDUCT
					.getCode());
			creditPolicy_ORDER_DEDUCT.setCredit(100);
			creditPolicy_ORDER_DEDUCT.setCurrency("CNY");

			GodPointsService.saveCreditPolicyReqWithORDER_DEDUCT(shopId,
					creditPolicy_ORDER_DEDUCT);
			Thread.sleep(500);

			GodPointsService.sendCredit((long) shopId, 20238699L);
			Thread.sleep(500);

			getProductTaxFeeReq = buildStandGetProductTaxFeeReq(productBean,
					(long) autotest_goodsOwnerId, null, false);

			OrderItemVoForTax orderItemVoForTax1 = getProductTaxFeeReq
					.getOrderGroups().get(0).getOrders().get(0).getOrderItems()
					.get(0);

			// 创建另一个商品
			OrderItemVoForTax orderItemVoForTax2 = new OrderItemVoForTax();

			orderItemVoForTax2
					.setCatalogId(productBean.getCatalogList().get(1));
			orderItemVoForTax2.setFreight(new BigDecimal(new Random()
					.nextInt(20) + 10));
			orderItemVoForTax2.setProdTaxRate(new BigDecimal("0.12"));
			orderItemVoForTax2.setProductId(productBean.getProductId());
			orderItemVoForTax2.setProductNum(1);
			orderItemVoForTax2.setProductPrice(new BigDecimal("1542.00"));

			getProductTaxFeeReq.getOrderGroups().get(0).getOrders().get(0)
					.getOrderItems().add(orderItemVoForTax2);

			// 定义买手下的优惠商品信息list
			List<SellerPromotionVo> sellerPromotionList = new ArrayList<SellerPromotionVo>();

			SellerPromotionVo sellerPromotion1 = new SellerPromotionVo();

			sellerPromotion1.setAmountCondition(new BigDecimal(100));
			sellerPromotion1.setId(123456789);
			sellerPromotion1.setName("自动化商家优惠活动");

			sellerPromotion1.setPromotionValue(new BigDecimal(12));
			sellerPromotion1.setQtyCondition(4);

			sellerPromotion1.setReducedAmount(new BigDecimal(15));
			sellerPromotion1.setType(PromotionTypeEnum.ReduceIfAmountEnough);

			sellerPromotion1.setApportions(Arrays.asList(
					new CatalogApportionVo(orderItemVoForTax1.getCatalogId(),
							orderItemVoForTax1.getProductNum()),
					new CatalogApportionVo(orderItemVoForTax2.getCatalogId(),
							orderItemVoForTax2.getProductNum())));

			sellerPromotionList.add(sellerPromotion1);

			getProductTaxFeeReq.getOrderGroups().get(0)
					.setSellerPromotionApportions(sellerPromotionList);
			
			getProductTaxFeeReq.getOrderGroups().get(0).getOrders().get(0)
					.setRegionDiscountRatio(new BigDecimal("7.00"));

			getProductTaxFeeReq.setDiscount(BigDecimal.ZERO);
			getProductTaxFeeReq.setShenqiProxyBuyOrder(true);
			getProductTaxFeeReq.setUserId(20238699L);
			getProductTaxFeeReq.setFreeShipAndTax(false);

			getProductTaxFeeCall.setData(getProductTaxFeeReq);
			getProductTaxFeeCall.callService();

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetProductTaxFee_020() {
		Logger.start(true, "单个商品，中免大会员");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createMultiCodeProxychain((int) cdfMembergoodsOwnerId, false);

			getProductTaxFeeReq = buildStandGetProductTaxFeeReq(productBean,
					cdfMembergoodsOwnerId, new BigDecimal("0.15"));

			OrderItemVoForTax orderItemVoForTax = getProductTaxFeeReq
					.getOrderGroups().get(0).getOrders().get(0).getOrderItems()
					.get(0);
			
			orderItemVoForTax.setSku("C052901");
			orderItemVoForTax.setProductRecordNo("C052901");
			
			getProductTaxFeeReq.setUserId(26080783L);
			getProductTaxFeeReq.setIntegralServiceType(2);
		 
			getProductTaxFeeCall.setData(getProductTaxFeeReq);
			getProductTaxFeeCall.callService();

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetProductTaxFee_021() {
		Logger.start(true, "多个商品，多个订单，中免大会员，使用积分");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createMultiCodeProxychain((int) cdfMembergoodsOwnerId, false);
			
			getProductTaxFeeReq = buildStandGetProductTaxFeeReq(productBean,
					cdfMembergoodsOwnerId, null);
			
			OrderVoForTax orderVoForTax1 = getProductTaxFeeReq.getOrderGroups().get(0).getOrders().get(0);

			OrderItemVoForTax orderItemVoForTax1 = orderVoForTax1
					.getOrderItems().get(0);
			
			orderItemVoForTax1.setSku("C052901");
			orderItemVoForTax1.setProductRecordNo("C052901");
			orderItemVoForTax1.setProductNum(1);
			orderItemVoForTax1.setProductPrice(new BigDecimal("1.50"));
			orderItemVoForTax1.setFreight(BigDecimal.ZERO);
			
			OrderItemVoForTax orderItemVoForTax2 = this.buildStandOrderItemVoForTax(productBean);
			
			orderItemVoForTax2.setSku("C052902");
			orderItemVoForTax2.setProductRecordNo("C052902");
			orderItemVoForTax2.setProductNum(1);
			orderItemVoForTax2.setProductPrice(new BigDecimal("1.50"));
			orderItemVoForTax2.setFreight(BigDecimal.ZERO);
			orderItemVoForTax2.setCatalogId(productBean.getCatalogList().get(1));
			
			orderVoForTax1.getOrderItems().add(orderItemVoForTax2);
			
			OrderItemVoForTax orderItemVoForTax3 = orderVoForTax1
					.getOrderItems().get(0);
			
			orderItemVoForTax3.setSku("C052899");
			orderItemVoForTax3.setProductRecordNo("C052899");
			orderItemVoForTax3.setProductNum(1);
			orderItemVoForTax3.setProductPrice(new BigDecimal("1.50"));
			orderItemVoForTax3.setFreight(BigDecimal.ZERO);
			
			OrderItemVoForTax orderItemVoForTax4 = this.buildStandOrderItemVoForTax(productBean);
			
			orderItemVoForTax4.setSku("C052900");
			orderItemVoForTax4.setProductRecordNo("C052900");
			orderItemVoForTax4.setProductNum(1);
			orderItemVoForTax4.setProductPrice(new BigDecimal("1.50"));
			orderItemVoForTax4.setFreight(BigDecimal.ZERO);
			orderItemVoForTax4.setCatalogId(productBean.getCatalogList().get(1));
			
			OrderVoForTax orderVoForTax2 = this.buildStandOrderVoForTax(productBean.getGoodsOwnerId(),
					Arrays.asList(orderItemVoForTax3, orderItemVoForTax4));
			
			getProductTaxFeeReq.getOrderGroups().get(0).getOrders().add(orderVoForTax2);
			
			getProductTaxFeeReq.setUserId(26080783L);
			getProductTaxFeeReq.setIntegralServiceType(2);
			getProductTaxFeeReq.setDiscount(BigDecimal.ZERO);
		 
			getProductTaxFeeCall.setData(getProductTaxFeeReq);
			getProductTaxFeeCall.callService();

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetProductTaxFee_022() {
		Logger.start(true, "多个商品，单个订单，中免大会员，使用积分");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createMultiCodeProxychain((int) cdfMembergoodsOwnerId, false);
			
			getProductTaxFeeReq = buildStandGetProductTaxFeeReq(productBean,
					cdfMembergoodsOwnerId, null);
			
			OrderVoForTax orderVoForTax1 = getProductTaxFeeReq.getOrderGroups().get(0).getOrders().get(0);

			OrderItemVoForTax orderItemVoForTax1 = orderVoForTax1
					.getOrderItems().get(0);
			
			orderItemVoForTax1.setSku("C052901");
			orderItemVoForTax1.setProductRecordNo("C052901");
			orderItemVoForTax1.setProductNum(1);
			orderItemVoForTax1.setProductPrice(new BigDecimal("517.88"));
			orderItemVoForTax1.setFreight(BigDecimal.ZERO);
			
			OrderItemVoForTax orderItemVoForTax2 = this.buildStandOrderItemVoForTax(productBean);
			
			orderItemVoForTax2.setSku("C052902");
			orderItemVoForTax2.setProductRecordNo("C052902");
			orderItemVoForTax2.setProductNum(1);
			orderItemVoForTax2.setProductPrice(new BigDecimal("195.54"));
			orderItemVoForTax2.setFreight(BigDecimal.ZERO);
			orderItemVoForTax2.setCatalogId(productBean.getCatalogList().get(1));
			
			AgentProductBean productBean1 = DGSQBuildProxyChainCallService
					.createMultiCodeProxychain((int) cdfMembergoodsOwnerId, false);
			
			OrderItemVoForTax orderItemVoForTax3 = this.buildStandOrderItemVoForTax(productBean1);
			
			orderItemVoForTax3.setSku("C052899");
			orderItemVoForTax3.setProductRecordNo("C052899");
			orderItemVoForTax3.setProductNum(1);
			orderItemVoForTax3.setProductPrice(new BigDecimal("195.54"));
			orderItemVoForTax3.setFreight(BigDecimal.ZERO);
			
			OrderItemVoForTax orderItemVoForTax4 = this.buildStandOrderItemVoForTax(productBean1);
			
			orderItemVoForTax4.setSku("C052900");
			orderItemVoForTax4.setProductRecordNo("C052900");
			orderItemVoForTax4.setProductNum(2);
			orderItemVoForTax4.setProductPrice(new BigDecimal("61.52"));
			orderItemVoForTax4.setFreight(BigDecimal.ZERO);
			orderItemVoForTax4.setCatalogId(productBean1.getCatalogList().get(1));
			
			orderVoForTax1.getOrderItems().add(orderItemVoForTax2);
			orderVoForTax1.getOrderItems().add(orderItemVoForTax3);
			orderVoForTax1.getOrderItems().add(orderItemVoForTax4);
			
			getProductTaxFeeReq.setUserId(26080783L);
			getProductTaxFeeReq.setIntegralServiceType(2);
			getProductTaxFeeReq.setDiscount(BigDecimal.ZERO);
		 
			getProductTaxFeeCall.setData(getProductTaxFeeReq);
			getProductTaxFeeCall.callService();

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_GetProductTaxFee_023() {
		Logger.start(true, "多个商品，多个订单，中免大会员，使用大会员代金券");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createMultiCodeProxychain((int) cdfMembergoodsOwnerId, false);

			getProductTaxFeeReq = buildStandGetProductTaxFeeReq(productBean,
					cdfMembergoodsOwnerId, new BigDecimal("0.15"), true);
			
			OrderItemVoForTax orderItemVoForTax = getProductTaxFeeReq
					.getOrderGroups().get(0).getOrders().get(0).getOrderItems()
					.get(0);
			
			orderItemVoForTax.setSku("C052901");
			orderItemVoForTax.setProductRecordNo("C052901");
			orderItemVoForTax.setProductNum(1);
			orderItemVoForTax.setProductPrice(new BigDecimal("50.00"));
			
			// 领取cdf优惠券
			CDFMemberService.getCdfCoupon(CouponTypeEnum.FULL_REDUCTION_COUPON.getCode(), 1,
					26080783L);

			CouponVo couponVo = getProductTaxFeeReq.getOrderGroups().get(0)
					.getSellerCoupon();

			couponVo.setCouponSource(1);
			couponVo.setCouponType(CouponTypeEnum.CASH_COUPON
					.getCode());
			couponVo.setCouponCode(CDFMemberService.getLatestUnuseCdfCoupon(
					26080783L, cdfMembergoodsOwnerId));
			
			getProductTaxFeeReq.setUserId(26080783L);
			getProductTaxFeeReq.setDiscount(BigDecimal.ZERO);
			getProductTaxFeeReq.setIntegralServiceType(2);
		 
			getProductTaxFeeCall.setData(getProductTaxFeeReq);
			getProductTaxFeeCall.callService();

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_GetProductTaxFee_024() {
		Logger.start(true, "多个商品，一个订单，带换购，中免大会员，使用大会员满减优惠券");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createMultiCodeProxychain((int) cdfMembergoodsOwnerId, false);

			getProductTaxFeeReq = buildStandGetProductTaxFeeReq(productBean,
					cdfMembergoodsOwnerId, new BigDecimal("0.15"), true);
			
			OrderItemVoForTax orderItemVoForTax1 = getProductTaxFeeReq
					.getOrderGroups().get(0).getOrders().get(0).getOrderItems()
					.get(0);
			
			orderItemVoForTax1.setSku("C052901");
			orderItemVoForTax1.setProductRecordNo("C052901");
			orderItemVoForTax1.setProductNum(1);
			orderItemVoForTax1.setProductPrice(new BigDecimal("50.00"));
			
			// 创建另一个商品
			OrderItemVoForTax orderItemVoForTax2 = new OrderItemVoForTax();

			orderItemVoForTax2
					.setCatalogId(productBean.getCatalogList().get(1));
			orderItemVoForTax2.setFreight(new BigDecimal(new Random()
					.nextInt(20) + 10));
			orderItemVoForTax2.setProductId(productBean.getProductId());
			orderItemVoForTax2.setProductNum(1);
			orderItemVoForTax2.setProductPrice(new BigDecimal("1542.00"));
			orderItemVoForTax2.setExchangeBuy(true);
			
			// 领取cdf优惠券
			CDFMemberService.getCdfCoupon(CouponTypeEnum.FULL_REDUCTION_COUPON.getCode(), 1,
					26080783L);

			CouponVo couponVo = getProductTaxFeeReq.getOrderGroups().get(0)
					.getSellerCoupon();

			couponVo.setCouponSource(1);
			couponVo.setCouponType(CouponTypeEnum.CASH_COUPON
					.getCode());
			couponVo.setCouponCode(CDFMemberService.getLatestUnuseCdfCoupon(
					26080783L, cdfMembergoodsOwnerId));
			
			getProductTaxFeeReq.setUserId(26080783L);
			getProductTaxFeeReq.setDiscount(BigDecimal.ZERO);
			getProductTaxFeeReq.setIntegralServiceType(2);
		 
			getProductTaxFeeCall.setData(getProductTaxFeeReq);
			getProductTaxFeeCall.callService();

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetProductTaxFee_025() {
		Logger.start(true, "单个订单，多个商品，包含多张买手优惠券，获得税费");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false);

			getProductTaxFeeReq = buildStandGetProductTaxFeeReq(productBean,
					(long) autotest_goodsOwnerId, new BigDecimal("0.15"), false);

			CouponVo couponVo1 = SqTradingCallService.createSellerCouponVo(
					20238699L, autotest_goodsOwnerId, new BigDecimal("50.00"),
					BigDecimal.TEN);

			CouponVo couponVo2 = SqTradingCallService.createSellerCouponVo(
					20238699L, autotest_goodsOwnerId, new BigDecimal("50.00"),
					new BigDecimal("15.00"));
			
			couponVo2.setCouponType(CouponTypeEnum.FULL_DISCOUNT_COUPON
					.getCode());
			
			getProductTaxFeeReq.getOrderGroups().get(0)
					.setSellerCoupons(Arrays.asList(couponVo1, couponVo2));

			// 创建另一个商品
			OrderItemVoForTax orderItemVoForTax2 = new OrderItemVoForTax();

			orderItemVoForTax2
					.setCatalogId(productBean.getCatalogList().get(1));
			orderItemVoForTax2.setFreight(new BigDecimal(new Random()
					.nextInt(20) + 10));
			orderItemVoForTax2.setProdTaxRate(new BigDecimal("0.12"));
			orderItemVoForTax2.setProductId(productBean.getProductId());
			orderItemVoForTax2.setProductNum(1);
			orderItemVoForTax2.setProductPrice(new BigDecimal("1542.00"));

			getProductTaxFeeReq.getOrderGroups().get(0).getOrders().get(0)
					.getOrderItems().add(orderItemVoForTax2);

			getProductTaxFeeCall.setData(getProductTaxFeeReq);
			getProductTaxFeeCall.callService();

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetProductTaxFee_026() {
		Logger.start(true, "单个订单，多个商品，一个优惠码，获得税费");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false);

			getProductTaxFeeReq = buildStandGetProductTaxFeeReq(productBean,
					(long) autotest_goodsOwnerId, new BigDecimal("0.15"), false);

			CouponVo couponVo1 = SqTradingCallService.createSellerCouponVo(
					20238699L, autotest_goodsOwnerId, new BigDecimal("50.00"),
					BigDecimal.TEN);
			
			couponVo1.setCouponMainType(CouponMainTypeEnum.PROMOTION_CODE.getCode());
			
			getProductTaxFeeReq.getOrderGroups().get(0)
					.setSellerCoupons(Arrays.asList(couponVo1));

			// 创建另一个商品
			OrderItemVoForTax orderItemVoForTax2 = new OrderItemVoForTax();

			orderItemVoForTax2
					.setCatalogId(productBean.getCatalogList().get(1));
			orderItemVoForTax2.setFreight(new BigDecimal(new Random()
					.nextInt(20) + 10));
			orderItemVoForTax2.setProdTaxRate(new BigDecimal("0.12"));
			orderItemVoForTax2.setProductId(productBean.getProductId());
			orderItemVoForTax2.setProductNum(1);
			orderItemVoForTax2.setProductPrice(new BigDecimal("1542.00"));

			getProductTaxFeeReq.getOrderGroups().get(0).getOrders().get(0)
					.getOrderItems().add(orderItemVoForTax2);

			getProductTaxFeeCall.setData(getProductTaxFeeReq);
			getProductTaxFeeCall.callService();

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetProductTaxFee_027() {
		Logger.start(true, "单个订单，多个商品，多个优惠码，获得税费失败");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false);

			getProductTaxFeeReq = buildStandGetProductTaxFeeReq(productBean,
					(long) autotest_goodsOwnerId, new BigDecimal("0.15"), false);

			CouponVo couponVo1 = SqTradingCallService.createSellerCouponVo(
					20238699L, autotest_goodsOwnerId, new BigDecimal("50.00"),
					BigDecimal.TEN);
			
			couponVo1.setCouponMainType(CouponMainTypeEnum.PROMOTION_CODE.getCode());
			
			CouponVo couponVo2 = SqTradingCallService.createSellerCouponVo(
					20238699L, autotest_goodsOwnerId, new BigDecimal("50.00"),
					BigDecimal.TEN);
			
			couponVo2.setCouponMainType(CouponMainTypeEnum.PROMOTION_CODE.getCode());
			
			getProductTaxFeeReq.getOrderGroups().get(0)
					.setSellerCoupons(Arrays.asList(couponVo1, couponVo2));

			// 创建另一个商品
			OrderItemVoForTax orderItemVoForTax2 = new OrderItemVoForTax();

			orderItemVoForTax2
					.setCatalogId(productBean.getCatalogList().get(1));
			orderItemVoForTax2.setFreight(new BigDecimal(new Random()
					.nextInt(20) + 10));
			orderItemVoForTax2.setProdTaxRate(new BigDecimal("0.12"));
			orderItemVoForTax2.setProductId(productBean.getProductId());
			orderItemVoForTax2.setProductNum(1);
			orderItemVoForTax2.setProductPrice(new BigDecimal("1542.00"));

			getProductTaxFeeReq.getOrderGroups().get(0).getOrders().get(0)
					.getOrderItems().add(orderItemVoForTax2);

			getProductTaxFeeCall.setData(getProductTaxFeeReq);
			getProductTaxFeeCall.callService();

			Logger.verifyEquals(400, getProductTaxFeeCall.getCode(), "验证code");
			Logger.verifyEquals(100, getProductTaxFeeCall.getBcode(), "验证bcode");
			Logger.verifyEquals("同一类型商家优惠券/码数量不能大于1", getProductTaxFeeCall.getMsg(),
					"验证msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetProductTaxFee_028() {
		Logger.start(true, "单个订单，多个商品，优惠券和优惠码混用，获得税费失败");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false);

			getProductTaxFeeReq = buildStandGetProductTaxFeeReq(productBean,
					(long) autotest_goodsOwnerId, new BigDecimal("0.15"), false);

			CouponVo couponVo1 = SqTradingCallService.createSellerCouponVo(
					20238699L, autotest_goodsOwnerId, new BigDecimal("50.00"),
					BigDecimal.TEN);
			
			couponVo1.setCouponMainType(CouponMainTypeEnum.PROMOTION_CODE.getCode());
			
			CouponVo couponVo2 = SqTradingCallService.createSellerCouponVo(
					20238699L, autotest_goodsOwnerId, new BigDecimal("50.00"),
					BigDecimal.TEN);
			
			getProductTaxFeeReq.getOrderGroups().get(0)
					.setSellerCoupons(Arrays.asList(couponVo1, couponVo2));

			// 创建另一个商品
			OrderItemVoForTax orderItemVoForTax2 = new OrderItemVoForTax();

			orderItemVoForTax2
					.setCatalogId(productBean.getCatalogList().get(1));
			orderItemVoForTax2.setFreight(new BigDecimal(new Random()
					.nextInt(20) + 10));
			orderItemVoForTax2.setProdTaxRate(new BigDecimal("0.12"));
			orderItemVoForTax2.setProductId(productBean.getProductId());
			orderItemVoForTax2.setProductNum(1);
			orderItemVoForTax2.setProductPrice(new BigDecimal("1542.00"));

			getProductTaxFeeReq.getOrderGroups().get(0).getOrders().get(0)
					.getOrderItems().add(orderItemVoForTax2);

			getProductTaxFeeCall.setData(getProductTaxFeeReq);
			getProductTaxFeeCall.callService();

			Logger.verifyEquals(400, getProductTaxFeeCall.getCode(), "验证code");
			Logger.verifyEquals(100, getProductTaxFeeCall.getBcode(), "验证bcode");
			Logger.verifyEquals("同一类型商家优惠券/码数量不能大于1", getProductTaxFeeCall.getMsg(),
					"验证msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetProductTaxFee_029() {
		Logger.start(true, "单个订单，多个商品，包含多个买手促销，获得税费");
		try {

//			Integer mchId = DGSQBaseService.createIndependenceMch("USA");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createIndependenceProxychain((int) autotest_goodsOwnerId, 0, false, false);

            AgentProductBean productBean2 = DGSQBuildProxyChainCallService
                    .createIndependenceProxychain((int) autotest_goodsOwnerId, 0, false, false);

			getProductTaxFeeReq = buildStandGetProductTaxFeeReq(productBean,
					(long) autotest_goodsOwnerId, null, true);

			OrderItemVoForTax orderItemVoForTax1 = getProductTaxFeeReq
					.getOrderGroups().get(0).getOrders().get(0).getOrderItems()
					.get(0);

			orderItemVoForTax1.setProductNum(1);
			orderItemVoForTax1.setProductPrice(new BigDecimal("426.00"));
			orderItemVoForTax1.setFullReductionFreeFreight(true);

			// 创建另一个商品
			OrderItemVoForTax orderItemVoForTax2 = new OrderItemVoForTax();

			orderItemVoForTax2
					.setCatalogId(productBean2.getCatalogList().get(1));
			orderItemVoForTax2.setProductId(productBean2.getProductId());
			orderItemVoForTax2.setProductNum(7);
			orderItemVoForTax2.setProductPrice(new BigDecimal("679.00"));
			orderItemVoForTax2.setFullReductionFreeFreight(true);

			getProductTaxFeeReq.getOrderGroups().get(0).getOrders().get(0)
					.getOrderItems().add(orderItemVoForTax2);

			// 定义买手下的优惠商品信息list
			List<SellerPromotionVo> sellerPromotionList = new ArrayList<SellerPromotionVo>();

			SellerPromotionVo sellerPromotion1 = new SellerPromotionVo();

			sellerPromotion1.setAmountCondition(new BigDecimal(3000));
			sellerPromotion1.setId(123456789);
			sellerPromotion1.setName("自动化商家优惠活动1");

			sellerPromotion1.setPromotionValue(new BigDecimal(300));
			sellerPromotion1.setQtyCondition(0);

			sellerPromotion1.setReducedAmount(new BigDecimal(300));
			sellerPromotion1.setType(PromotionTypeEnum.ReduceIfAmountEnough);

			sellerPromotion1.setApportions(Arrays.asList(
					new CatalogApportionVo(orderItemVoForTax2.getCatalogId(),
							orderItemVoForTax2.getProductNum())));

			// 定义买手下的优惠商品信息list
			SellerPromotionVo sellerPromotion2 = new SellerPromotionVo();

			sellerPromotion2.setAmountCondition(new BigDecimal(3000));
			sellerPromotion2.setId(97087);
			sellerPromotion2.setName("自动化商家优惠活动1");

			sellerPromotion2.setPromotionValue(new BigDecimal("0.8"));
			sellerPromotion2.setQtyCondition(1);

			sellerPromotion2.setReducedAmount(new BigDecimal("85.2"));
			sellerPromotion2.setType(PromotionTypeEnum.DiscountIfCountEnough);

			sellerPromotion2.setApportions(Arrays.asList(
					new CatalogApportionVo(orderItemVoForTax1.getCatalogId(),
							orderItemVoForTax1.getProductNum())));

			sellerPromotionList.add(sellerPromotion1);
			sellerPromotionList.add(sellerPromotion2);

			getProductTaxFeeReq.getOrderGroups().get(0)
					.setSellerPromotionApportions(sellerPromotionList);

			getProductTaxFeeReq.setDiscount(BigDecimal.ZERO);

            CouponVo coupon = getProductTaxFeeReq.getOrderGroups().get(0).getSellerCoupon();

            coupon.setCouponType(1);
            coupon.setCouponSource(0);
            coupon.setCouponValue(new BigDecimal("45.00"));
            coupon.setApplianceType(CouponApplianceTypeEnum.SPEC_RODUCT);
            coupon.setApplianceTargets(Arrays.asList(orderItemVoForTax1.getProductId()));

			getProductTaxFeeCall.setData(getProductTaxFeeReq);
			getProductTaxFeeCall.callService();

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	public static void main(String[] args) {

		BigDecimal a = new BigDecimal("106");
		BigDecimal b = new BigDecimal("10");

		System.out.println(a.divideAndRemainder(b)[0]);
	}
}
